package com.example.lay.ui;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.ToggleButton;

/**
 * Created by cuilei on 2014/12/10.
 */
public class MyToggleSwitchActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toggle_switch);
        final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linear);
        CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    linearLayout.setOrientation(LinearLayout.VERTICAL);
                } else {
                    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                }
            }
        };
        ((ToggleButton) findViewById(R.id.toggle)).setOnCheckedChangeListener(listener);
        ((Switch) findViewById(R.id.switcher)).setOnCheckedChangeListener(listener);
    }
}
